package com.sdhs.analyze.service.monitor;

import com.sdhs.analyze.bean.*;
import com.sdhs.analyze.bean.monitorinfo.GantryMonitorInfo;
import com.sdhs.analyze.bean.network.NetWork;
import com.sdhs.analyze.bean.org.OrgInfo;
import com.sdhs.analyze.common.BizConstants;
import com.sdhs.analyze.dao.device.DeviceMapper;
import com.sdhs.analyze.utils.NumberUtils;
import com.sdhs.analyze.utils.StatusCheckUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class DeviceService {

    @Autowired
    private NodeStatusService nodeStatusService;

    @Autowired
    private DeviceMapper deviceMapper;

    @Autowired
    private NetWorkService netWorkService;


    private String split = "|";

    /**
     * 前端工控机监测
     *
     * @param nodeStatusMap
     * @param orgInfo
     * @param nodeTypeMap
     * @return
     */
    public void frontServerMonitor(
            OrgInfo orgInfo,
            Map<String, InfoNodeStatus> nodeStatusMap,
            Map<String, DicNodeType> nodeTypeMap,
            InfoNodeStatus parentNodeStatus,
            GantryMonitorInfo gantryMonitorInfo) {
        DicNodeType frontServerNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_SERVER);
        DicNodeType frontSoftNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_SOFT_STATUS);
        DicNodeType frontLoadNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_LOAD_AVG);
        DicNodeType frontOverTradeNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_OVER_TRADE);
        DicNodeType frontTransErrTradeNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_TRANS_ERR_TRADE);
        DicNodeType frontOverVehNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_OVER_VEH_DATA);
        DicNodeType frontTransErrVehNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_TRANS_ERR_VEH_DATA);
        DicNodeType frontDiskDataNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_DISK_DATA);
        DicNodeType frontDiskRunNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_DISK_RUN);
        DicNodeType frontCpuRateNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_CPU_RATE);
        DicNodeType frontMemoryRateNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_MEMORY_RATE);
        DicNodeType frontBeidouStatusNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_BEIDOU_STATUS);
        DicNodeType frontNetWorkStatusNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_NETWORK_STATUS);
        DicNodeType frontHeartBeatNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_HEART_BEAT);
        DicNodeType frontHeartBeatValidStatusNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_FRONT_HEART_BEAT_VALID_STATUS);

        /* 获取当前前端工控机状态信息 */
        List<InfoGantryStatusFront> gantryHeartbeatList = deviceMapper.selectGantryFrontOnline(orgInfo.getOrgId());

        /* 初始化前端工控机节点状态 */
        InfoNodeStatus frontServerNodeStatus = nodeStatusService.makeNodeStatus(
                frontServerNodeType, orgInfo.getOrgId(),
                orgInfo.getOrgName() + split + frontServerNodeType.getNodeTypeName(),
                orgInfo.getOrgId(), BizConstants.NODE_STATUS_UNKNOWN, orgInfo.getOrgId(), "", new Date(0));

        Date now = new Date();

        int totalCnt = 0;

        int normalCnt = 0;

        for (int i = 0; i < gantryHeartbeatList.size(); i++) {
            InfoGantryStatusFront igsf = gantryHeartbeatList.get(i);
            Integer frontComputerOrder = igsf.getFrontComputerOrder();
            String name = frontComputerOrder == 1 ? "主机" : "备机";
            String gantryId = igsf.getGantryId();
            String nodeId = gantryId + split + frontComputerOrder;
            String nodeName = orgInfo.getOrgName() + split + frontServerNodeType.getNodeTypeName() + split + name;
            InfoNodeStatus frontServerComputerNodeStatus =
                    nodeStatusService.makeNodeStatus(frontServerNodeType, nodeId,
                            nodeName, gantryId, BizConstants.NODE_STATUS_UNKNOWN,
                            gantryId, "", new Date(0));

            Date frontStateTime = igsf.getFrontStateTime();

            // 前端软件
            String softState = gantryHeartbeatList.get(i).getFrontSoftState();
            String anotherSoftState = null;
            if (gantryHeartbeatList.size() > 1) {
                anotherSoftState = gantryHeartbeatList.get((i + 1) % 2).getFrontSoftState();
            }
            // 判断标准：主备全为异常则异常，单个异常视为轻微异常，否则正常
            int softStatusRange = BizConstants.STATUS_RANGE_UNKNOWN;
            if (softState.contains("1")) {
                softStatusRange = BizConstants.STATUS_RANGE_2;
                if (anotherSoftState == null || anotherSoftState.contains("1")) {
                    softStatusRange = BizConstants.STATUS_RANGE_3;
                }
            } else {
                softStatusRange = BizConstants.STATUS_RANGE_1;
            }

//            // 判断标准：单个判断异常
//            int softStatusRange =
//                    softState.contains("1") ? BizConstants.STATUS_RANGE_2 : BizConstants.STATUS_RANGE_1;
            InfoNodeStatus frontSoftNodeStatus = StatusCheckUtils.checkByRange(
                    softStatusRange, frontStateTime, frontSoftNodeType,
                    nodeId, nodeName + split + frontSoftNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontSoftNodeStatus.getKey(), frontSoftNodeStatus);

            // 硬件资源平均负载状态
            String frontLoadAverage = igsf.getFrontLoadAverage();
            Double tmpDouble = Double.parseDouble(frontLoadAverage);
            Integer frontLoadAverageInt = tmpDouble.intValue();
            InfoNodeStatus frontLoadAverageNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    frontLoadAverageInt, frontStateTime, frontLoadNodeType,
                    nodeId, nodeName + split + frontLoadNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontLoadAverageNodeStatus.getKey(), frontLoadAverageNodeStatus);

            // 积压通行流水状态
            Integer frontOverTradeCount = igsf.getFrontOverTradeCount();
            InfoNodeStatus frontOverTradeCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    frontOverTradeCount, frontStateTime, frontOverTradeNodeType,
                    nodeId, nodeName + split + frontOverTradeNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontOverTradeCountNodeStatus.getKey(), frontOverTradeCountNodeStatus);

            // 传输异常通行流水状态
            Integer frontTransErrTradeCount = igsf.getFrontTransErrTradeCount();
            InfoNodeStatus frontTransErrTradeCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    frontTransErrTradeCount, frontStateTime, frontTransErrTradeNodeType,
                    nodeId, nodeName + split + frontTransErrTradeNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontTransErrTradeCountNodeStatus.getKey(), frontTransErrTradeCountNodeStatus);

            // 积压牌识流水状态
            Integer frontOverVehDataCount = igsf.getFrontOverVehDataCount();
            InfoNodeStatus frontOverVehDataCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    frontOverVehDataCount, frontStateTime, frontOverVehNodeType,
                    nodeId, nodeName + split + frontOverVehNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontOverVehDataCountNodeStatus.getKey(), frontOverVehDataCountNodeStatus);

            // 传输异常牌识流水状态
            Integer frontTransErrVehDataCount = igsf.getFrontTransErrVehDataCount();
            InfoNodeStatus frontTransErrVehDataCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    frontTransErrVehDataCount, frontStateTime, frontTransErrVehNodeType,
                    nodeId, nodeName + split + frontTransErrVehNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontTransErrVehDataCountNodeStatus.getKey(), frontTransErrVehDataCountNodeStatus);

            // 数据盘使用状态
            String frontDiskDataLeftSize = igsf.getFrontDiskDataLeftSize();
            String frontDiskDataTotalSize = igsf.getFrontDiskDataTotalSize();
            Integer diskDataUsage = getUsage(frontDiskDataTotalSize, frontDiskDataLeftSize);
            InfoNodeStatus frontDiskDataUsageNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    diskDataUsage, frontStateTime, frontDiskDataNodeType,
                    nodeId, nodeName + split + frontDiskDataNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontDiskDataUsageNodeStatus.getKey(), frontDiskDataUsageNodeStatus);

            // 运行盘使用状态
            String frontDiskRunLeftSize = igsf.getFrontDiskRunLeftSize();
            String frontDiskRunTotalSize = igsf.getFrontDiskRunTotalSize();
            Integer diskRunUsage = getUsage(frontDiskRunTotalSize, frontDiskRunLeftSize);
            InfoNodeStatus frontDiskRunUsageNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    diskRunUsage, frontStateTime, frontDiskRunNodeType,
                    nodeId, nodeName + split + frontDiskRunNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontDiskRunUsageNodeStatus.getKey(), frontDiskRunUsageNodeStatus);

            // 心跳传输状态
            // 按最后一次心跳时间和当前时间间隔（分钟）计算
            Long timeDiff = (now.getTime() - frontStateTime.getTime()) / 1000 / 60;
            InfoNodeStatus heartBeatNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    timeDiff.intValue(), frontStateTime, frontHeartBeatNodeType,
                    nodeId, nodeName + split + frontHeartBeatNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(heartBeatNodeStatus.getKey(), heartBeatNodeStatus);

            // 心跳数据异常状态
            // 如运行盘使用量和总量显示0，则认为心跳数据异常
            int heartBeatValidStatusRange = BizConstants.STATUS_RANGE_UNKNOWN;
            if (frontDiskDataLeftSize != null && frontDiskRunTotalSize != null
                    && frontDiskDataLeftSize.equals("0") && frontDiskRunTotalSize.equals("0")) {
                heartBeatValidStatusRange = BizConstants.STATUS_RANGE_2;
            } else {
                heartBeatValidStatusRange = BizConstants.STATUS_RANGE_1;
            }
            InfoNodeStatus heartBeatValidNodeStatus = StatusCheckUtils.checkByRange(
                    heartBeatValidStatusRange, frontStateTime, frontHeartBeatValidStatusNodeType,
                    nodeId, nodeName + split + frontHeartBeatValidStatusNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(heartBeatValidNodeStatus.getKey(), heartBeatValidNodeStatus);


            // CPU使用状态
            String frontCpuRate = igsf.getFrontCpuRate();
            tmpDouble = Double.parseDouble(frontCpuRate);
            Integer frontCpuRateInt = tmpDouble.intValue();
            InfoNodeStatus frontCpuNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    frontCpuRateInt, frontStateTime, frontCpuRateNodeType,
                    nodeId, nodeName + split + frontCpuRateNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontCpuNodeStatus.getKey(), frontCpuNodeStatus);

            // 物理内存使用状态
            String frontMemory = igsf.getFrontMemoryRate();
            tmpDouble = Double.parseDouble(frontMemory);
            Integer frontMemoryInt = tmpDouble.intValue();
            InfoNodeStatus frontMemoryNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    frontMemoryInt, frontStateTime, frontMemoryRateNodeType,
                    nodeId, nodeName + split + frontMemoryRateNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(frontMemoryNodeStatus.getKey(), frontMemoryNodeStatus);

            // 前端北斗授时服务
            String frontBeidouState = igsf.getFrontBeidouState();
            int frontBeidouRange = frontBeidouState.equals("1") ? BizConstants.STATUS_RANGE_1 : BizConstants.STATUS_RANGE_2;
            InfoNodeStatus beiDouNodeStatus = StatusCheckUtils.checkByRange(
                    frontBeidouRange, frontStateTime, frontBeidouStatusNodeType,
                    nodeId, nodeName + split + frontBeidouStatusNodeType.getNodeTypeName(),
                    gantryId, frontServerComputerNodeStatus);
            nodeStatusMap.put(beiDouNodeStatus.getKey(), beiDouNodeStatus);

            // 前端工控机网络状态
            NetWork netWork = netWorkService.getNetworkStatus(nodeId, frontServerNodeType.getNodeType());
            if (netWork != null) {
                int value = 0;
                if (netWork.getStatus() != BizConstants.NODE_STATUS_NORMAL) {
                    value = (int) ((now.getTime() - netWork.getExcTime().getTime()) / 60000);
                }
                InfoNodeStatus netWorkNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                        value, netWork.getStatusChangeTime(), frontNetWorkStatusNodeType,
                        nodeId, nodeName + split + frontNetWorkStatusNodeType.getNodeTypeName(),
                        gantryId, frontServerComputerNodeStatus);
                nodeStatusMap.put(netWorkNodeStatus.getKey(), netWorkNodeStatus);
            }

            StatusCheckUtils.checkParentNodeStatus(frontServerComputerNodeStatus.getStatus(),
                    frontServerComputerNodeStatus.getStatusCheckTime(),
                    frontServerNodeStatus);
            nodeStatusMap.put(frontServerComputerNodeStatus.getKey(), frontServerComputerNodeStatus);

            if (frontServerComputerNodeStatus.getStatus() == BizConstants.NODE_STATUS_NORMAL) {

                normalCnt++;
            }
            totalCnt++;
        }

        gantryMonitorInfo.getFrontServer().setStatus(frontServerNodeStatus.getStatus());

        gantryMonitorInfo.getFrontServer().setRemark(normalCnt + split + totalCnt);

        if (frontServerNodeStatus.getStatus() > gantryMonitorInfo.getDevice().getStatus()) {

            gantryMonitorInfo.getDevice().setStatus(frontServerNodeStatus.getStatus());
        }

        StatusCheckUtils.checkParentNodeStatus(frontServerNodeStatus.getStatus(),
                frontServerNodeStatus.getStatusCheckTime(),
                parentNodeStatus);
    }

    /**
     * 后台服务器监测
     *
     * @param nodeStatusMap
     * @param orgInfo
     * @param nodeTypeMap
     * @return
     */
    public void backServerMonitor(
            OrgInfo orgInfo,
            Map<String, InfoNodeStatus> nodeStatusMap,
            Map<String, DicNodeType> nodeTypeMap,
            InfoNodeStatus parentNodeStatus,
            GantryMonitorInfo gantryMonitorInfo) {
        DicNodeType backServerNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_SERVER);
        DicNodeType backSoftNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_SOFT_STATUS);
        DicNodeType backLoadNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_LOAD_AVG);
        DicNodeType backOverTradeNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_OVER_TRADE);
        DicNodeType backTransErrTradeNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_TRANS_ERR_TRADE);
        DicNodeType backOverVehNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_OVER_VEH_DATA);
        DicNodeType backTransErrVehNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_TRANS_ERR_VEH_DATA);
        DicNodeType backOverVehPicNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_OVER_VEH_PIC);
        DicNodeType backTransErrVehPicNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_TRANS_ERR_VEH_PIC);
        DicNodeType backDiskDataNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_DISK_DATA);
        DicNodeType backDiskRunNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_DISK_RUN);
        DicNodeType backCpuRateNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_CPU_RATE);
        DicNodeType backMemoryRateNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_MEMORY_RATE);
        DicNodeType backBeidouStatusNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_BEIDOU_STATUS);
        DicNodeType backNetWorkStatusNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_BACK_NETWORK_STATUS);

        List<InfoGantryStatusBack> gantryHeartbeatList = deviceMapper.selectGantryBackOnline(orgInfo.getOrgId());

        Date now = new Date();

        /* 初始化后台服务器节点状态 */
        InfoNodeStatus backServerNodeStatus = nodeStatusService.makeNodeStatus(
                backServerNodeType, orgInfo.getOrgId(),
                orgInfo.getOrgName() + split + backServerNodeType.getNodeTypeName(),
                orgInfo.getOrgId(), BizConstants.NODE_STATUS_UNKNOWN, orgInfo.getOrgId(), "", new Date(0));

        String id = orgInfo.getOrgId();

        int totalCnt = 0;

        int normalCnt = 0;

        for (int i = 0; i < gantryHeartbeatList.size(); i++) {
            InfoGantryStatusBack igsf = gantryHeartbeatList.get(i);
            Integer backComputerOrder = igsf.getBackComputerOrder();
            String name = backComputerOrder == 1 ? "主机" : "备机";
            String nodeId = id + split + backComputerOrder;
            String nodeName = orgInfo.getOrgName() + split + backServerNodeType.getNodeTypeName() + split + name;
            InfoNodeStatus backServerComputerNodeStatus = nodeStatusService.makeNodeStatus(
                    backServerNodeType, nodeId, nodeName, id,
                    BizConstants.NODE_STATUS_UNKNOWN, id, "", new Date(0));

            Date backStateTime = igsf.getBackStateTime();

            // 后台软件
            String softState = gantryHeartbeatList.get(i).getBackSoftState();
            String anotherSoftState = null;
            if (gantryHeartbeatList.size() > 1) {
                anotherSoftState = gantryHeartbeatList.get((i + 1) % 2).getBackSoftState();
            }
            // 判断标准：主备全为异常则异常，单个异常视为轻微异常，否则正常
            int backSoftStatusRange = BizConstants.STATUS_RANGE_UNKNOWN;
            if (softState.contains("1")) {
                backSoftStatusRange = BizConstants.STATUS_RANGE_2;
                if (anotherSoftState == null || anotherSoftState.contains("1")) {
                    backSoftStatusRange = BizConstants.STATUS_RANGE_3;
                }
            } else {
                backSoftStatusRange = BizConstants.STATUS_RANGE_1;
            }
//            // 判断标准：单个判断异常
//            int backSoftStatusRange =
//                    softState.contains("1") ? BizConstants.STATUS_RANGE_2 : BizConstants.STATUS_RANGE_1;
            InfoNodeStatus backSoftNodeStatus = StatusCheckUtils.checkByRange(
                    backSoftStatusRange, backStateTime, backSoftNodeType,
                    nodeId, nodeName + split + backSoftNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(backSoftNodeStatus.getKey(), backSoftNodeStatus);

            // 硬件资源平均负载状态
            String backLoadAverage = igsf.getBackLoadAverage();
            Double tmpDouble = Double.parseDouble(backLoadAverage);
            Integer backLoadAverageInt = tmpDouble.intValue();
            InfoNodeStatus frontLoadAverageNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backLoadAverageInt, backStateTime, backLoadNodeType,
                    nodeId, nodeName + split + backLoadNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontLoadAverageNodeStatus.getKey(), frontLoadAverageNodeStatus);

            // 积压通行流水状态
            Integer backOverTradeCount = igsf.getBackOverTradeCount();
            InfoNodeStatus frontOverTradeCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backOverTradeCount, backStateTime, backOverTradeNodeType,
                    nodeId, nodeName + split + backOverTradeNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontOverTradeCountNodeStatus.getKey(), frontOverTradeCountNodeStatus);

            // 传输异常通行流水状态
            Integer backTransErrTradeCount = igsf.getBackTransErrTradeCount();
            InfoNodeStatus frontTransErrTradeCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backTransErrTradeCount, backStateTime, backTransErrTradeNodeType,
                    nodeId, nodeName + split + backTransErrTradeNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontTransErrTradeCountNodeStatus.getKey(), frontTransErrTradeCountNodeStatus);

            // 积压牌识流水状态
            Integer backOverVehDataCount = igsf.getBackOverVehDataCount();
            InfoNodeStatus frontOverVehDataCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backOverVehDataCount, backStateTime, backOverVehNodeType,
                    nodeId, nodeName + split + backOverVehNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontOverVehDataCountNodeStatus.getKey(), frontOverVehDataCountNodeStatus);

            // 传输异常牌识流水状态
            Integer backTransErrVehDataCount = igsf.getBackTransErrVehDataCount();
            InfoNodeStatus frontTransErrVehDataCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backTransErrVehDataCount, backStateTime, backTransErrVehNodeType,
                    nodeId, nodeName + split + backTransErrVehNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontTransErrVehDataCountNodeStatus.getKey(), frontTransErrVehDataCountNodeStatus);

            // 积压牌识图片状态
            Integer backOverVehPicCount = igsf.getBackOverVehDataCount();
            InfoNodeStatus backOverVehPicCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backOverVehPicCount, backStateTime, backOverVehPicNodeType,
                    nodeId, nodeName + split + backOverVehPicNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(backOverVehPicCountNodeStatus.getKey(), backOverVehPicCountNodeStatus);

            // 传输异常牌识图片状态
            Integer backTransErrVehPicVehCount = igsf.getBackTransErrVehPicCount();
            InfoNodeStatus backTransErrVehPicVehCountNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backTransErrVehPicVehCount, backStateTime, backTransErrVehPicNodeType,
                    nodeId, nodeName + split + backTransErrVehPicNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(backTransErrVehPicVehCountNodeStatus.getKey(), backTransErrVehPicVehCountNodeStatus);

            // 数据盘使用状态
            String frontDiskDataLeftSize = igsf.getBackDiskDataLeftSize();
            String frontDiskDataTotalSize = igsf.getBackDiskDataTotalSize();
            Integer diskDataUsage = getUsage(frontDiskDataTotalSize, frontDiskDataLeftSize);
            InfoNodeStatus frontDiskDataUsageNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    diskDataUsage, backStateTime, backDiskDataNodeType,
                    nodeId, nodeName + split + backDiskDataNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontDiskDataUsageNodeStatus.getKey(), frontDiskDataUsageNodeStatus);

            // 运行盘使用状态
            String backDiskRunLeftSize = igsf.getBackDiskRunLeftSize();
            String backDiskRunTotalSize = igsf.getBackDiskRunTotalSize();
            Integer diskRunUsage = getUsage(backDiskRunTotalSize, backDiskRunLeftSize);
            InfoNodeStatus frontDiskRunUsageNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    diskRunUsage, backStateTime, backDiskRunNodeType,
                    nodeId, nodeName + split + backDiskRunNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontDiskRunUsageNodeStatus.getKey(), frontDiskRunUsageNodeStatus);

            // CPU使用状态
            String backCpuRate = igsf.getBackCPURate();
            tmpDouble = Double.parseDouble(backCpuRate);
            Integer backCpuRateInt = tmpDouble.intValue();
            InfoNodeStatus frontCpuNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backCpuRateInt, backStateTime, backCpuRateNodeType,
                    nodeId, nodeName + split + backCpuRateNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontCpuNodeStatus.getKey(), frontCpuNodeStatus);

            // 物理内存使用状态
            String backMemory = igsf.getBackMemoryRate();
            tmpDouble = Double.parseDouble(backMemory);
            Integer backMemoryInt = tmpDouble.intValue();
            InfoNodeStatus frontMemoryNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    backMemoryInt, backStateTime, backMemoryRateNodeType,
                    nodeId, nodeName + split + backMemoryRateNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(frontMemoryNodeStatus.getKey(), frontMemoryNodeStatus);

            // 后台北斗授时服务
            String backBeidouState = igsf.getBackBeidouState();
            int backBeidouRange = backBeidouState.equals("1") ? BizConstants.STATUS_RANGE_1 : BizConstants.STATUS_RANGE_2;
            InfoNodeStatus beiDouNodeStatus = StatusCheckUtils.checkByRange(
                    backBeidouRange, backStateTime, backBeidouStatusNodeType,
                    nodeId, nodeName + split + backBeidouStatusNodeType.getNodeTypeName(),
                    id, backServerComputerNodeStatus);
            nodeStatusMap.put(beiDouNodeStatus.getKey(), beiDouNodeStatus);

            // 后台服务器网络状态
            NetWork netWork = netWorkService.getNetworkStatus(nodeId, backServerNodeType.getNodeType());
            if (netWork != null) {
                int value = 0;
                if (netWork.getStatus() != BizConstants.NODE_STATUS_NORMAL) {
                    value = (int) ((now.getTime() - netWork.getExcTime().getTime()) / 60000);
                }
                InfoNodeStatus netWorkNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                        value, netWork.getStatusChangeTime(), backNetWorkStatusNodeType,
                        nodeId, nodeName + split + backNetWorkStatusNodeType.getNodeTypeName(),
                        id, backServerComputerNodeStatus);
                nodeStatusMap.put(netWorkNodeStatus.getKey(), netWorkNodeStatus);
            }

            StatusCheckUtils.checkParentNodeStatus(backServerComputerNodeStatus.getStatus(),
                    backServerComputerNodeStatus.getStatusCheckTime(),
                    backServerNodeStatus);
            nodeStatusMap.put(backServerComputerNodeStatus.getKey(), backServerComputerNodeStatus);

            if (backServerComputerNodeStatus.getStatus() == BizConstants.NODE_STATUS_NORMAL) {

                normalCnt++;
            }
            totalCnt++;
        }

        gantryMonitorInfo.getBackServer().setStatus(backServerNodeStatus.getStatus());

        gantryMonitorInfo.getBackServer().setRemark(normalCnt + split + totalCnt);

        if (backServerNodeStatus.getStatus() > gantryMonitorInfo.getDevice().getStatus()) {

            gantryMonitorInfo.getDevice().setStatus(backServerNodeStatus.getStatus());
        }

        StatusCheckUtils.checkParentNodeStatus(backServerNodeStatus.getStatus(),
                backServerNodeStatus.getStatusCheckTime(),
                parentNodeStatus);
    }

    /**
     * 牌识设备监测
     *
     * @param nodeStatusMap
     * @param orgInfo
     * @param nodeTypeMap
     * @return
     */
    public void cameraMonitor(
            OrgInfo orgInfo,
            Map<String, InfoNodeStatus> nodeStatusMap,
            Map<String, DicNodeType> nodeTypeMap,
            InfoNodeStatus parentNodeStatus,
            GantryMonitorInfo gantryMonitorInfo) {

        DicNodeType cameraNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_CAMERA);
        DicNodeType cameraConnectNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_CAMERA_CONNECT_STATUS);
        DicNodeType cameraWorkNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_CAMERA_WORK_STATUS);
        DicNodeType cameraNetWorkNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_CAMERA_NETWORK_STATUS);

        List<InfoGantryStatusCamera> cameraHeartbeatList = deviceMapper.selectGantryCameraOnline(orgInfo.getOrgId());

        /* 初始化牌识节点状态 */
        InfoNodeStatus cameraNodeStatus = nodeStatusService.makeNodeStatus(
                cameraNodeType, orgInfo.getOrgId(),
                orgInfo.getOrgName() + split + cameraNodeType.getNodeTypeName(),
                orgInfo.getOrgId(), BizConstants.NODE_STATUS_UNKNOWN, orgInfo.getOrgId(), "", new Date(0));

        Date now = new Date();

        int totalCnt = 0;

        int normalCnt = 0;

        for (int i = 0; i < cameraHeartbeatList.size(); i++) {
            InfoGantryStatusCamera camera = cameraHeartbeatList.get(i);
            String gantryId = camera.getGantryId();
            Integer cameraNum = camera.getCameraNum();
            Date createTime = camera.getCreateTime();
            String nodeId = gantryId + split + cameraNum;
            String nodeName = orgInfo.getOrgName() + split + cameraNodeType.getNodeTypeName() + split + cameraNum;

            InfoNodeStatus cameraDeviceNodeStatus = nodeStatusService.makeNodeStatus(
                    cameraNodeType, nodeId, nodeName, gantryId,
                    BizConstants.NODE_STATUS_UNKNOWN, gantryId, "", new Date(0));

            // 连接状态 0-断开，1-连接
            String connectStatus = camera.getConnectStatus();
            int connectStatusRange = connectStatus.equals("1") ? BizConstants.STATUS_RANGE_1 : BizConstants.STATUS_RANGE_2;
            InfoNodeStatus cameraConnectNodeStatus = StatusCheckUtils.checkByRange(
                    connectStatusRange, createTime, cameraConnectNodeType,
                    nodeId, nodeName + split + cameraConnectNodeType.getNodeTypeName(),
                    gantryId, cameraDeviceNodeStatus);
            nodeStatusMap.put(cameraConnectNodeStatus.getKey(), cameraConnectNodeStatus);

            // 工作状态 0-断开，1-连接
            String workStatus = camera.getConnectStatus();
            int workStatusRange = workStatus.equals("1") ? BizConstants.STATUS_RANGE_1 : BizConstants.STATUS_RANGE_2;
            InfoNodeStatus cameraWorkNodeStatus = StatusCheckUtils.checkByRange(
                    workStatusRange, createTime, cameraWorkNodeType,
                    nodeId, nodeName + split + cameraWorkNodeType.getNodeTypeName(),
                    gantryId, cameraDeviceNodeStatus);
            nodeStatusMap.put(cameraWorkNodeStatus.getKey(), cameraWorkNodeStatus);

            // 牌识设备网络状态
            NetWork netWork = netWorkService.getNetworkStatus(nodeId, cameraNodeType.getNodeType());
            if (netWork != null) {
                int value = 0;
                if (netWork.getStatus() != BizConstants.NODE_STATUS_NORMAL) {
                    value = (int) ((now.getTime() - netWork.getExcTime().getTime()) / 60000);
                }
                InfoNodeStatus netWorkNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                        value, netWork.getStatusChangeTime(), cameraNetWorkNodeType,
                        nodeId, nodeName + split + cameraNetWorkNodeType.getNodeTypeName(),
                        gantryId, cameraDeviceNodeStatus);
                nodeStatusMap.put(netWorkNodeStatus.getKey(), netWorkNodeStatus);
            }

            StatusCheckUtils.checkParentNodeStatus(cameraDeviceNodeStatus.getStatus(),
                    cameraDeviceNodeStatus.getStatusCheckTime(),
                    cameraNodeStatus);
            nodeStatusMap.put(cameraDeviceNodeStatus.getKey(), cameraDeviceNodeStatus);

            if (cameraDeviceNodeStatus.getStatus() == BizConstants.NODE_STATUS_NORMAL) {

                normalCnt++;
            }
            totalCnt++;
        }

        gantryMonitorInfo.getCamera().setStatus(cameraNodeStatus.getStatus());

        gantryMonitorInfo.getCamera().setRemark(normalCnt + split + totalCnt);

        if (cameraNodeStatus.getStatus() > gantryMonitorInfo.getDevice().getStatus()) {

            gantryMonitorInfo.getDevice().setStatus(cameraNodeStatus.getStatus());
        }

        StatusCheckUtils.checkParentNodeStatus(cameraNodeStatus.getStatus(),
                cameraNodeStatus.getStatusCheckTime(),
                parentNodeStatus);
    }


    /**
     * RSU设备监测
     *
     * @param nodeStatusMap
     * @param orgInfo
     * @param nodeTypeMap
     * @return
     */
    public void rsuMonitor(
            OrgInfo orgInfo,
            Map<String, InfoNodeStatus> nodeStatusMap,
            Map<String, DicNodeType> nodeTypeMap,
            InfoNodeStatus parentNodeStatus,
            GantryMonitorInfo gantryMonitorInfo) {

        DicNodeType rsuNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_RSU);
        DicNodeType rsuStatusNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_RSU_STATUS);
        DicNodeType rsuPsamNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_RSU_PSAM_CARD_STATUS);
        DicNodeType rsuControllerNetworkNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_RSU_CONTROLLER_NETWORK);
        DicNodeType rsuNetworkNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_RSU_NETWORK_STATUS);

        List<InfoGantryStatusRSU> rsuHeartbeatList = deviceMapper.selectGantryRsuOnline(orgInfo.getOrgId());
        boolean allExcFlag = false;

        /* 初始化RSU节点状态 */
        InfoNodeStatus rsuNodeStatus = nodeStatusService.makeNodeStatus(
                rsuNodeType, orgInfo.getOrgId(),
                orgInfo.getOrgName() + split + rsuNodeType.getNodeTypeName(),
                orgInfo.getOrgId(), BizConstants.NODE_STATUS_UNKNOWN, orgInfo.getOrgId(), "", new Date(0));

        Date now = new Date();

        int totalCnt = 0;

        int normalCnt = 0;

        for (int i = 0; i < rsuHeartbeatList.size(); i++) {
            InfoGantryStatusRSU rsu = rsuHeartbeatList.get(i);
            String gantryId = rsu.getGantryId();
            String controlOrder = rsu.getControlId();
            Date createTime = rsu.getCreateTime();
            String nodeId = gantryId + split + controlOrder;
            String nodeName = orgInfo.getOrgName() + split + rsuNodeType.getNodeTypeName() + controlOrder;

            InfoGantryStatusRSU anotherRsu = null;
            if (rsuHeartbeatList.size() > 1) {
                anotherRsu = rsuHeartbeatList.get((i + 1) % 2);
            }

            InfoNodeStatus rsuDeviceNodeStatus = nodeStatusService.makeNodeStatus(
                    rsuNodeType, nodeId, nodeName, gantryId,
                    BizConstants.NODE_STATUS_UNKNOWN, gantryId, "", new Date(0));

            // 路侧单元主状态参数 11 21 表示正常，否则表示异常
            // 20200529 duanxin 判断逻辑调整：任意一个控制器主状态异常，判断为异常
//            String rsuStatus = rsu.getRSUStatus();
//            String anotherState = anotherRsu.getRSUStatus();
//            int rsuStatusRange;
//            if(!rsuStatus.equals("11") && !rsuStatus.equals("21")) {
//                rsuStatusRange = BizConstants.STATUS_RANGE_2;
//                if(anotherState == null || (!anotherState.equals("11") && !anotherState.equals("21"))) {
//                    rsuStatusRange = BizConstants.STATUS_RANGE_3;
//                    allExcFlag = true;
//                }
//            }
//            else {
//                rsuStatusRange = BizConstants.STATUS_RANGE_1;
//            }
            String rsuStatus = rsu.getRSUStatus();
            int rsuStatusRange;
            if (!rsuStatus.equals("11") && !rsuStatus.equals("21")) {
                rsuStatusRange = BizConstants.STATUS_RANGE_2;
            } else {
                rsuStatusRange = BizConstants.STATUS_RANGE_1;
            }

            // RSU主备控制器间连接状态 1 通讯正常，2 通讯异常
            String controlNetwrok = rsu.getControlNetWrok();
            String anotherControlNetwrok = (anotherRsu == null ? null : anotherRsu.getControlNetWrok());
            int controlNetwrokRange;
            if (!controlNetwrok.equals("1")) {
                controlNetwrokRange = BizConstants.STATUS_RANGE_2;
                if (anotherControlNetwrok != null && !anotherControlNetwrok.equals("1")) {
                    controlNetwrokRange = BizConstants.STATUS_RANGE_3;
                    allExcFlag = true;
                }
            } else {
                controlNetwrokRange = BizConstants.STATUS_RANGE_1;
            }

            // PSAM状态
            Integer psamNormalCnt = rsu.getPsamCnt();
            Integer otherPsamNormalCnt = (anotherRsu == null ? null : anotherRsu.getPsamNormalCnt());
            int psamStatusRange;
            if (psamNormalCnt == 0) {
                psamStatusRange = BizConstants.STATUS_RANGE_2;
                if (otherPsamNormalCnt == null || otherPsamNormalCnt == 0) {
                    psamStatusRange = BizConstants.STATUS_RANGE_3;
                    allExcFlag = true;
                }
            } else {
                psamStatusRange = BizConstants.STATUS_RANGE_1;
            }

            /* 如主备均发生异常，则异常节点状态均取range3 */
            if (allExcFlag) {
//                rsuStatusRange = (rsuStatusRange == BizConstants.STATUS_RANGE_2)
//                        ? BizConstants.STATUS_RANGE_3 : rsuStatusRange;
                controlNetwrokRange = (controlNetwrokRange == BizConstants.STATUS_RANGE_2)
                        ? BizConstants.STATUS_RANGE_3 : controlNetwrokRange;
                psamStatusRange = (psamStatusRange == BizConstants.STATUS_RANGE_2)
                        ? BizConstants.STATUS_RANGE_3 : psamStatusRange;
            }

            // 路侧单元主状态参数
            InfoNodeStatus rsuStatusNodeStatus = StatusCheckUtils.checkByRange(
                    rsuStatusRange, createTime, rsuStatusNodeType,
                    nodeId, nodeName + split + rsuStatusNodeType.getNodeTypeName(),
                    gantryId, rsuDeviceNodeStatus);
            nodeStatusMap.put(rsuStatusNodeStatus.getKey(), rsuStatusNodeStatus);

            // RSU主备控制器间连接状态 1 通讯正常，2 通讯异常
            InfoNodeStatus controlNetWrokNodeStatus = StatusCheckUtils.checkByRange(
                    controlNetwrokRange, createTime, rsuControllerNetworkNodeType,
                    nodeId, nodeName + split + rsuControllerNetworkNodeType.getNodeTypeName(),
                    gantryId, rsuDeviceNodeStatus);
            nodeStatusMap.put(controlNetWrokNodeStatus.getKey(), controlNetWrokNodeStatus);

            // PSAM状态
            InfoNodeStatus psamNodeStatus = StatusCheckUtils.checkByRange(
                    psamStatusRange, createTime, rsuPsamNodeType,
                    nodeId, nodeName + split + rsuPsamNodeType.getNodeTypeName(),
                    gantryId, rsuDeviceNodeStatus);
            nodeStatusMap.put(controlNetWrokNodeStatus.getKey(), controlNetWrokNodeStatus);

            // RSU设备网络状态
            NetWork netWork = netWorkService.getNetworkStatus(nodeId, rsuNodeType.getNodeType());
            if (netWork != null) {
                int value = 0;
                if (netWork.getStatus() != BizConstants.NODE_STATUS_NORMAL) {
                    value = (int) ((now.getTime() - netWork.getExcTime().getTime()) / 60000);
                }
                InfoNodeStatus netWorkNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                        value, netWork.getStatusChangeTime(), rsuNetworkNodeType,
                        nodeId, nodeName + split + rsuNetworkNodeType.getNodeTypeName(),
                        gantryId, rsuDeviceNodeStatus);
                nodeStatusMap.put(netWorkNodeStatus.getKey(), netWorkNodeStatus);
            }

            StatusCheckUtils.checkParentNodeStatus(rsuDeviceNodeStatus.getStatus(),
                    rsuDeviceNodeStatus.getStatusCheckTime(),
                    rsuNodeStatus);
            nodeStatusMap.put(rsuDeviceNodeStatus.getKey(), rsuDeviceNodeStatus);

            if (rsuDeviceNodeStatus.getStatus() == BizConstants.NODE_STATUS_NORMAL) {

                normalCnt++;
            }
            totalCnt++;
        }

        gantryMonitorInfo.getRsu().setStatus(rsuNodeStatus.getStatus());

        gantryMonitorInfo.getRsu().setRemark(normalCnt + split + totalCnt);

        if (rsuNodeStatus.getStatus() > gantryMonitorInfo.getDevice().getStatus()) {

            gantryMonitorInfo.getDevice().setStatus(rsuNodeStatus.getStatus());
        }

        StatusCheckUtils.checkParentNodeStatus(rsuNodeStatus.getStatus(),
                rsuNodeStatus.getStatusCheckTime(),
                parentNodeStatus);
    }

    /**
     * RSU设备监测
     *
     * @param nodeStatusMap
     * @param orgInfo
     * @param nodeTypeMap
     * @return
     */
    public void antennalMonitor(
            OrgInfo orgInfo,
            Map<String, InfoNodeStatus> nodeStatusMap,
            Map<String, DicNodeType> nodeTypeMap,
            InfoNodeStatus parentNodeStatus,
            GantryMonitorInfo gantryMonitorInfo) {

        DicNodeType antennalNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_ANTENNA);
        DicNodeType antennalCommNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_RSU_ANTENNA_COMM_STATUS);
        DicNodeType antennalEmissionNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_RSU_ANTENNA_EMISSION_STATUS);
        DicNodeType antennalReceiveStatusNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_RSU_ANTENNA_RECEIVE_STATUS);

        List<InfoGantryStatusRSUAntennal> heartbeatList = deviceMapper.selectGantryRsuAntennalOnline(orgInfo.getOrgId());

        /* 初始化天线头节点状态 */
        InfoNodeStatus antennalNodeStatus = nodeStatusService.makeNodeStatus(
                antennalNodeType, orgInfo.getOrgId(),
                orgInfo.getOrgName() + split + antennalNodeType.getNodeTypeName(),
                orgInfo.getOrgId(), BizConstants.NODE_STATUS_UNKNOWN, orgInfo.getOrgId(), "", new Date(0));

        int totalCnt = 0;

        int normalCnt = 0;

        for (int i = 0; i < heartbeatList.size(); i++) {
            InfoGantryStatusRSUAntennal antennal = heartbeatList.get(i);
            String gantryId = orgInfo.getOrgId();
            String antennaId = antennal.getAntennaId();
            Date checkTime = antennal.getCheckTime();
            String nodeId = gantryId + split + antennaId;
            String nodeName = orgInfo.getOrgName() + split + antennalNodeType.getNodeTypeName() + antennaId;

            InfoNodeStatus antennalDeviceNodeStatus = nodeStatusService.makeNodeStatus(
                    antennalNodeType, nodeId, nodeName, gantryId,
                    BizConstants.NODE_STATUS_UNKNOWN, gantryId, "", new Date(0));

            // RSU 天线头
            // 通信状态(1 位)，1 正常，2 异常；
            // 天线信道(1 位)，1 信道 1，2 信道2；功率等级(2 位)，取值 01～31；
            // 发射状态(1 位)，1 正常，2 异常；接收状态(1 位)，1 正常，2 异常；
            String status = antennal.getStatus();
            // 天线头通信状态 1 正常，2 异常；
            String sub1 = status.substring(0, 1);
            InfoNodeStatus antennalCommNodeStatus = StatusCheckUtils.checkByRange(
                    sub1.equals("1") ? BizConstants.STATUS_RANGE_1 : BizConstants.STATUS_RANGE_2,
                    checkTime, antennalCommNodeType,
                    nodeId, nodeName + split + antennalCommNodeType.getNodeTypeName(),
                    gantryId, antennalDeviceNodeStatus);
            nodeStatusMap.put(antennalCommNodeStatus.getKey(), antennalCommNodeStatus);

            // 天线头发射状态 1 正常，2 异常；
            String sub2 = status.substring(4, 5);
            InfoNodeStatus antennalEmissionNodeStatus = StatusCheckUtils.checkByRange(
                    sub2.equals("1") ? BizConstants.STATUS_RANGE_1 : BizConstants.STATUS_RANGE_2,
                    checkTime, antennalEmissionNodeType,
                    nodeId, nodeName + split + antennalEmissionNodeType.getNodeTypeName(),
                    gantryId, antennalDeviceNodeStatus);
            nodeStatusMap.put(antennalEmissionNodeStatus.getKey(), antennalEmissionNodeStatus);

            // 天线头接收状态 1 正常，2 异常；
            String sub3 = status.substring(5, 6);
            InfoNodeStatus antennalReceiveNodeStatus = StatusCheckUtils.checkByRange(
                    sub3.equals("1") ? BizConstants.STATUS_RANGE_1 : BizConstants.STATUS_RANGE_2,
                    checkTime, antennalReceiveStatusNodeType,
                    nodeId, nodeName + split + antennalReceiveStatusNodeType.getNodeTypeName(),
                    gantryId, antennalDeviceNodeStatus);
            nodeStatusMap.put(antennalReceiveNodeStatus.getKey(), antennalReceiveNodeStatus);

            /* 判断父节点的状态 */
            StatusCheckUtils.checkParentNodeStatus(antennalDeviceNodeStatus.getStatus(),
                    antennalDeviceNodeStatus.getStatusCheckTime(),
                    antennalNodeStatus);

            nodeStatusMap.put(antennalDeviceNodeStatus.getKey(), antennalDeviceNodeStatus);

            if (antennalDeviceNodeStatus.getStatus() == BizConstants.NODE_STATUS_NORMAL) {

                normalCnt++;
            }
            totalCnt++;
        }

        gantryMonitorInfo.getAntenna().setStatus(antennalNodeStatus.getStatus());

        gantryMonitorInfo.getAntenna().setRemark(normalCnt + split + totalCnt);

        if (antennalNodeStatus.getStatus() > gantryMonitorInfo.getDevice().getStatus()) {

            gantryMonitorInfo.getDevice().setStatus(antennalNodeStatus.getStatus());
        }

        /* 判断父节点的状态 */
        StatusCheckUtils.checkParentNodeStatus(antennalNodeStatus.getStatus(),
                antennalNodeStatus.getStatusCheckTime(),
                parentNodeStatus);
    }

    /**
     * 智能机柜设备监测
     *
     * @param nodeStatusMap
     * @param orgInfo
     * @param nodeTypeMap
     * @return
     */
    public void cabinetMonitor(
            OrgInfo orgInfo,
            Map<String, InfoNodeStatus> nodeStatusMap,
            Map<String, DicNodeType> nodeTypeMap,
            InfoNodeStatus parentNodeStatus,
            GantryMonitorInfo gantryMonitorInfo) {

        DicNodeType cabinetNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_CABINET);
        DicNodeType cabinetNetworkNodeType = nodeTypeMap.get(BizConstants.NODE_TYPE_CABINET_NETWORK);

        /* 初始化机柜节点状态 */
        InfoNodeStatus cabinetNodeStatus = nodeStatusService.makeNodeStatus(
                cabinetNodeType, orgInfo.getOrgId(),
                orgInfo.getOrgName() + split + cabinetNodeType.getNodeTypeName(),
                orgInfo.getOrgId(), BizConstants.NODE_STATUS_UNKNOWN, orgInfo.getOrgId(), "", new Date(0));

        String gantryId = orgInfo.getOrgId();
        String nodeId = gantryId;
        String nodeName = orgInfo.getOrgName() + split + cabinetNodeType.getNodeTypeName();

        Date now = new Date();

        // 机柜设备网络状态
        NetWork netWork = netWorkService.getNetworkStatus(nodeId, cabinetNodeType.getNodeType());
        if (netWork != null) {
            int value = 0;
            if (netWork.getStatus() != BizConstants.NODE_STATUS_NORMAL) {
                value = (int) ((now.getTime() - netWork.getExcTime().getTime()) / 60000);
            }
            InfoNodeStatus netWorkNodeStatus = StatusCheckUtils.checkStatusByThreshold(
                    value, netWork.getStatusChangeTime(), cabinetNetworkNodeType,
                    nodeId, nodeName + split + cabinetNetworkNodeType.getNodeTypeName(),
                    gantryId, cabinetNodeStatus);
            nodeStatusMap.put(netWorkNodeStatus.getKey(), netWorkNodeStatus);
        }

        nodeStatusMap.put(cabinetNodeStatus.getKey(), cabinetNodeStatus);

        gantryMonitorInfo.getCabinet().setStatus(cabinetNodeStatus.getStatus());

        gantryMonitorInfo.getCabinet().setRemark("");

        if (cabinetNodeStatus.getStatus() > gantryMonitorInfo.getDevice().getStatus()) {

            gantryMonitorInfo.getDevice().setStatus(cabinetNodeStatus.getStatus());
        }

        /* 判断父节点的状态 */
        StatusCheckUtils.checkParentNodeStatus(cabinetNodeStatus.getStatus(),
                cabinetNodeStatus.getStatusCheckTime(),
                parentNodeStatus);
    }

    /**
     * 获得使用百分比
     *
     * @param totalSize
     * @param leftSize
     * @return
     */
    public Integer getUsage(
            String totalSize, String leftSize) {
        float left;
        if (leftSize.contains("KiB")) {
            left = Float.parseFloat(NumberUtils.parseNum(leftSize));
        } else if (leftSize.contains("GiB")) {
            left = Float.parseFloat(NumberUtils.parseNum(leftSize));
            left = left * 1024F;
        } else if (leftSize.contains("TiB")) {
            left = Float.parseFloat(NumberUtils.parseNum(leftSize));
            left = left * 1024F * 1024F;
        } else {
            left = Float.parseFloat(leftSize);
        }

        float total = 0;
        if (totalSize.contains("KiB")) {
            total = Float.parseFloat(NumberUtils.parseNum(totalSize));
        } else if (totalSize.contains("GiB")) {
            total = Float.parseFloat(NumberUtils.parseNum(totalSize));
            total = total * 1024F;
        } else if (totalSize.contains("TiB")) {
            total = Float.parseFloat(NumberUtils.parseNum(totalSize));
            total = total * 1024F * 1024F;
        } else {
            total = Float.parseFloat(totalSize);
        }
        Float value = (total - left) / total * 100;
        return value.intValue();
    }

}
